package com.wuzheng.wisgo.sanitation.cloud.controller.dict;


import com.wuzheng.wisgo.sanitation.cloud.repository.entity.dict.BaEnum;
import com.wuzheng.wisgo.sanitation.cloud.model.dict.BaEnumCriteria;
import com.wuzheng.wisgo.sanitation.cloud.service.dict.EnumService;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.constant.SysRespEnum;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author：sp
 * @date：Created in 2019-10-09
 * @description：字典控制器
 * @modified By：sp
 * @version: 1.0
 */
@RestController
@RequestMapping("/enum")
@Api(value = "EnumCtrl", tags = "字典接口")
public class EnumCtrl extends BaseController {

    @Autowired
    private EnumService enumService;

    /**
     * 获取字典列表
     */
    @PostMapping(value = "/tree")
    @ApiOperation(value = "获取字典树列表")
    public Result<Map<String, Object>> list() {
        return this.success(SysRespEnum.SUCCESS.getMessage(), enumService.selectTreeList());
    }

    /**
     * 获取字典列表
     */
    @PostMapping(value = "/fetchList")
    @ApiOperation(value = "获取分页字典列表")
    public Result<List<BaEnum>> list(@RequestBody BaEnumCriteria baEnumCriteria) {
        return this.success(enumService.selectPage(baEnumCriteria));
    }

    /**
     * 新增字典
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增字典")
    public Result<String> add(BaEnum baEnum) {
        enumService.insert(baEnum);
        return this.success();
    }

    /**
     * 删除字典
     */
    @PostMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除字典")
    public Result<String> delete(@PathVariable("id") Long id) {
        enumService.deleteById(id);
        return this.success();
    }

    /**
     * 修改字典
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改字典")
    public Result<String> update(BaEnum baEnum) {
        enumService.updateById(baEnum);
        return this.success();
    }

    /**
     * 获取字典
     */
    @GetMapping(value = "/get/{id}")
    @ApiOperation(value = "获取字典")
    public Result<BaEnum> get(@PathVariable("id") Long id) {
        return this.success(enumService.selectById(id));
    }
}

